const path = require('path');
const HtmlWebpackPlugin = require("html-webpack-plugin");
const CopyWebpackPlugin = require("copy-webpack-plugin");
module.exports ={
   entry:path.resolve(__dirname,'../src/index.js'),
   output:{
    path:path.resolve(__dirname,'../build'),
    filename:"./js/main.js",
    publicPath:'/'
   },
   plugins:[
    //生成html 模板
    new HtmlWebpackPlugin({
        template: path.resolve(__dirname, "../public/index.html")
    }),
    //打包public
    new CopyWebpackPlugin({
        patterns: [{
          from: path.resolve(__dirname, "../public"),
          to: "public",
          globOptions: {
            ignore: ["**/index.html"]
          }
        }],
      })
    ],
    module: {
      rules: [
        //我们刚开始路由中渲染的是html类型，需要使用html-loader
       {
        test: /\.ejs$/,
          loader: 'ejs-loader',
          options: {
            variable: 'data', // 可以在模块当中使用data进行数据处理
          }
        },
        {
          test: /\.css$/i,
          use: [
            //use中loader加载是有顺序的，先下后上，注意有的loader需要按照顺序书写
            "style-loader",
            'css-loader'
          ]
        }
      ]
    },
    
    mode:"production",
    resolve:{
      //配置别名
      alias:{
        $V:path.resolve(__dirname,'../src/views'),
        $r:path.resolve(__dirname,"../src/routes"),
        $a:path.resolve(__dirname, "../src/api"),
      },
      //配置引入文件后缀省略
      extensions:['.js','.json','.ejs']
    }

}